﻿using Houtel.IBll;
using Houtel.IDal;
using Houtel.Model;

namespace Houtel.Bll
{
    public class UserBll : IUserBll
    {
        private readonly IBaseDal<UserInfo> dal;

        public UserBll(IBaseDal<UserInfo> dal)
        {
            this.dal = dal;
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <param name="usex"></param>
        /// <returns></returns>
        public IQueryable<UserInfo> GetList(string? uname, DateTime? date, DateTime? time, string? usex)
        {
            try
            {
                var list = dal.GetList();
                if (!string.IsNullOrEmpty(uname))
                {
                    list = list.Where(x => x.Uname == uname);
                }
                if (date != null)
                {
                    list = list.Where(x => x.Udate > date);
                }
                if (time != null)
                {
                    list = list.Where(x => x.Udate < time);
                }
                if (!string.IsNullOrEmpty(usex))
                {
                    list = list.Where(x => x.Usex == usex);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="Uzhang"></param>
        /// <param name="upwd"></param>
        /// <returns></returns>
        public async Task<dynamic> Login(string Uzhang, string upwd)
        {
            try
            {
                var list = await dal.GetValue(x => x.Uzhang == Uzhang);
                if (list != null)
                {
                    if (list.Upwd == upwd)
                    {
                        if (list.Gid == 1)
                        {
                            return list;
                        }
                        return 3;
                    }
                    return 2;
                }
                return 1;
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
